package com.itheima.article.controller;


import com.itheima.article.dto.ArticleHomeDto;
import com.itheima.article.pojo.ApArticle;
import com.itheima.article.service.ApArticleService;
import com.itheima.common.constants.BusinessConstants;
import com.itheima.common.vo.PageResultVo;
import com.itheima.common.vo.ResultVo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RestController;
import com.itheima.core.controller.AbstractCoreController;

import java.util.Map;

/**
 * @description <p>已发布的文章信息</p>
 *
 * @version 1.0
 * @package com.itheima.article.controller
 */
@Api(value="ApArticleController",tags = "已发布的文章信息")
@RestController
@RequestMapping("/article")
public class ApArticleController extends AbstractCoreController<ApArticle> {

    private ApArticleService apArticleService;

    @Autowired
    public ApArticleController(ApArticleService apArticleService) {
        super(apArticleService);
        this.apArticleService=apArticleService;
    }


    /**
     * 加载默认第一页
     * @param dto
     * @return
     */
    @PostMapping("/load")
    public PageResultVo load(@RequestBody ArticleHomeDto dto){
       PageResultVo<ApArticle> vo= apArticleService.pageList(dto, BusinessConstants.ArticleConstants.LOAD_NEW);
       return vo;
    }

    /**
     * 加载下一页
     * @param dto
     * @return
     */
    @PostMapping("/loadmore")
    public PageResultVo loadmore(@RequestBody ArticleHomeDto dto){
        PageResultVo<ApArticle> vo= apArticleService.pageList(dto, BusinessConstants.ArticleConstants.LOAD_MORE);
        return vo;
    }


    /**
     * 加载最新的
     * @param dto
     * @return
     */
    @PostMapping("/loadnew")
    public PageResultVo loadnew(@RequestBody ArticleHomeDto dto){
        PageResultVo<ApArticle> vo= apArticleService.pageList(dto, BusinessConstants.ArticleConstants.LOAD_NEW);
        return vo;
    }

    /**
     * 查询文章信息详情
     * @param map
     * @return
     */
    @PostMapping("/load_article_info")
    public ResultVo loadArticleInfo(@RequestBody Map<String,String> map){
        Map<String,Object> resultMap =apArticleService.loadArticleInfo(map);
        return ResultVo.ok(resultMap);
    }

}

